package com.converters;

import com.domain.WriteData;
import com.enums.Alignment;
import com.enums.DataTypeEnum;
import com.enums.TextLevEnum;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

public class ListConverter implements Converter {

    /**
     * 数据转换
     * @param key
     * @param objList
     * @return
     */
    public WriteData convertToWriteData(String key, Object objList, Alignment alignment, TextLevEnum levEnum) {
        WriteData writeData = new WriteData(key);
        writeData.setKey(key);
        writeData.setValue(objList);
        writeData.setDataType(DataTypeEnum.LIST);
        List<List<WriteData>> listValue = new ArrayList();
        if (Objects.nonNull(objList)) {
            Iterator var5 = ((Iterable)objList).iterator();

            while(var5.hasNext()) {
                Object obj = var5.next();
                listValue.add(BeanConverter.beanToWriteData(obj));
            }
        }

        writeData.setListValue(listValue);
        return writeData;
    }
}
